package com.ruoyi.hr.controller.hr.entryexitmanage.reinstatedmanage;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.service.AuthorityService;
import com.ruoyi.hr.service.CompanysService;
import com.ruoyi.hr.service.DepartmentsService;
import com.ruoyi.hr.service.JobsService;
import com.ruoyi.hr.service.entryexitmanage.EntryExitManageService;
import com.ruoyi.hr.service.entryexitmanage.reinstatedmanage.ReinstatedManageService;
import com.ruoyi.hr.util.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author zeo
 * @explain 老员工复职管理
 * @date 2020/4/13
 */
@Controller
@RequestMapping("entryExitManage/reinstatedManage")
public class ReinstatedManageController extends BaseController {

    @Autowired
    AuthorityService authorityService;

    @Autowired
    ReinstatedManageService reinstatedManageService;

    @Autowired
    private CompanysService companysService;

    @Autowired
    JobsService jobsService;

    @Autowired
    EntryExitManageService entryExitManageService;

    @Autowired
    private DepartmentsService departmentsService;

    private String prefix = "hr/entryexitmanage/reinstatedmanage";

    @GetMapping()
    public String reinstatedManage() {
        return prefix + "/reinstatedManage";
    }

    @RequestMapping("/findReinstatedList")
    @ResponseBody
    public TableDataInfo findReinstatedList(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        return getDataTable(reinstatedManageService.findReinstatedList(map, authority));
    }

    @RequestMapping("/findReinstatedHistoryList")
    @ResponseBody
    public TableDataInfo findReinstatedHistoryList(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        return getDataTable(reinstatedManageService.findReinstatedHistoryList(map, authority));
    }

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        Map<String, Object> map = reinstatedManageService.findReinstated(id);
        Long compId = Long.valueOf(String.valueOf(map.get("CompId"))).longValue();
        Long depId = Long.valueOf(String.valueOf(map.get("DepId"))).longValue();

        mmap.put("emp", map);
        //公司
        mmap.put("companys", companysService.findAllCompanys(null));
        //部门
        mmap.put("departments", departmentsService.findDep((long) compId));
        //岗位
        mmap.put("jobs", jobsService.findJobs((long) depId));
        //签约单位
        mmap.put("contract", entryExitManageService.getContract());

        return prefix + "/edit";
    }

    @RequestMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@RequestParam Map map) {
        return toAjax(reinstatedManageService.edit(map));
    }

    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    @RequestMapping("/findEmpList")
    @ResponseBody
    public TableDataInfo findEmpList(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        startPage();
        return getDataTable(reinstatedManageService.findEmpList(map, authority));
    }

    @RequestMapping("/add")
    @ResponseBody
    public BaseResult add(String allEid) {
        return reinstatedManageService.add(allEid);
    }

    @RequestMapping("/procedure")
    @ResponseBody
    public BaseResult procedure(String allId,String procedure) {
        return reinstatedManageService.procedure(allId,procedure);
    }

    @GetMapping("/reinstatedHistory")
    public String reinstatedHistory() {
        return prefix + "/reinstatedHistory";
    }


}
